fun main() {
    //不取名字的函数叫做匿名函数
    val total = "Mississippi".count()

    val totalS = "Mississippi".count { it == 's' }

    println(total)
    println(totalS)

    /*匿名函数也有类型，匿名函数可以当作变量赋值给函数类型变量，就像其他变量一样，
    * 匿名函数不需要return关键字来返回数据，自动返回函数最后一行语句的结果*/
    //变量的类型是一个匿名函数
    val blessingFunction1: () -> String = {
        val holiday = "New Year."
        "Happy $holiday"
    }

    val blessingFunction2: (String) -> String = { name ->
        val holiday = "New Year."
        "$name, Happy $holiday"
    }

    //只有一个参数的匿名函数时，可以用it来表示参数名
    val blessingFunction3: (String) -> String = {
        val holiday = "New Year."
        "$it, Happy $holiday"
    }

    //类型推断
    val blessingFunction4 = {
        val holiday = "New Year."
        "Happy $holiday"
    }

    //正常带参数写法
    val blessingFunction5: (String, Int) -> String = { name, year ->
        val holiday = "New Year."
        "$name, Happy $holiday $year"
    }

    //带参数的类型推断
    val blessingFunction6 = { name: String, year: Int ->
        val holiday = "New Year."
        "$name, Happy $holiday $year"
    }

    println(blessingFunction1())
    println(blessingFunction2("Jack"))
    println(blessingFunction3("Jack"))
    println (blessingFunction4())
    println(blessingFunction5("Jack",2027))
    println(blessingFunction6("Jack", 2027))

}